﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UploadMultiPhoto.ascx.cs"
    Inherits="Besture.UI.Admin.Control.UploadMultiPhoto" %>
<script type="text/javascript">
    /*上传商品图片*/
    $(document).ready(function () {
        /*模板图片控件*/
        setTimeout(function () {
            $("#uploadify<%=PhotoDivID %>").uploadify({
                'swf': '/Admin/PlugIn/jquery.uploadify/uploadify.swf',
                'method': 'get',
                'uploader': '/Admin/Control/UploadMultiPhoto.aspx',
                'formData': { 'FolderPath': '<%=FolderPath %>', 'NeedThumbnail': '<%=NeedThumbnail %>', 'ThumbnailFolderPath': '<%=ThumbnailFolderPath %>', 'ThumbnailWidth': '<%=ThumbnailWidth %>', 'ThumbnailHeight': '<%=ThumbnailHeight %>', 'NeedThumbnailThree': '<%=NeedThumbnailThree %>', 'ThumbnailFolderPathThree': '<%=ThumbnailFolderPathThree %>', 'ThumbnailWidthThree': '<%=ThumbnailWidthThree %>', 'ThumbnailHeightThree': '<%=ThumbnailHeightThree %>' },
                'fileObjName': "ProductPhotoFile",
                'folder': '/Upload/',
                'queueID': 'fileQueue<%=PhotoDivID %>',
                'auto': true,
                'multi': true,
                'fileTypeExts': "*.jpg;*.png;*.gif;",
                'fileTypeDesc': 'Web Image Files (.JPG, .GIF, .PNG)',
                'buttonImage': '/Admin/PlugIn/jquery.uploadify/browse-btn.png',
                'cancelImg': '/Admin/PlugIn/jquery.uploadify/uploadify-cancel.png',
                'width': 120,
                'height': 30,
                'wmode': 'transparent',
                'onUploadSuccess': function (file, serverData, response) {//上传完成时触发（每个文件触发一次）
                    if (!response) {
                        alert("网络异常，上传失败！");
                    } else {
                        if (serverData != "0") {
                            var count = parseInt($("#<%=hfCount.ClientID %>").val())+1;
                            /*if (count <= 5) {
                                $("#<%=hfCount.ClientID %>").val(count);
                            } else {
                                alert('只能上传5张图片！');
                                return;
                            }*/
                            var serverDataArgs = serverData.split("|");
                            var imgUrl = serverDataArgs[0];
                            var timestamp = serverDataArgs[2];
                            /*将新添加模板图片次数保存在隐藏控件hidUploadProModeTime中*/
                            var strhtml = "";
                            strhtml = strhtml + ("<div class='element' id='" + timestamp + "'>");
                            strhtml = strhtml + ("    <div>");
                            strhtml = strhtml + ("         <img src='<%=ThumbnailFolderPath %>" + imgUrl + "' alt='' />");
                            strhtml = strhtml + ("    </div>");
                            //strhtml = strhtml + ("    <p style='margin: 0em 0;'>");
                            //strhtml = strhtml + ("        <input ID='Input_" + timestamp + "' Name='Input_" + timestamp + "' type='text' value='' />");
                            //strhtml = strhtml + ("    </p>");
                            strhtml = strhtml + ("    <p  class='buttonP'>");
                            strhtml = strhtml + ("        <img src='/Admin/Themes/Images/del.gif' alt='删除图片' class='delPhoto' /><a href=\"javascript:DelPhoto('" + timestamp + "')\">删除</a>");
                            strhtml = strhtml + ("    </p>");
                            strhtml = strhtml + ("</div>");
                            /*将图片HTML加和指定TD*/
                            $("#<%=PhotoDivID %>").append(strhtml);
                            //添加图片地址集合
                            $("#<%=txtAddImgUrlArgs.ClientID %>").val($("#<%=txtAddImgUrlArgs.ClientID %>").val() + imgUrl + ",");
                            $("#<%=txtAddImgRemarParamIDkArgs.ClientID %>").val($("#<%=txtAddImgRemarParamIDkArgs.ClientID %>").val() + "Input_" + timestamp + ",");
                            //添加图片数量标记
                            $("#<%=txtAllImage.ClientID %>").val($("#<%=txtAllImage.ClientID %>").val() + "i");
                        }
                    }
                }
            });
        }, 10);

    });

    function DelPhoto(divID) {
        if (confirm("确定要删除此图片吗？")) {
            //删除图片DIV
            $("#" + divID).remove();
            $("#<%=txtDelIdArgs.ClientID %>").val($("#<%=txtDelIdArgs.ClientID %>").val() + divID + ",");
            //删除对应的文本记录
            var allimg = $("#<%=txtAllImage.ClientID %>").val();
            if (allimg != "") {
                $("#<%=txtAllImage.ClientID %>").val(allimg.substr(0, allimg.length -1));
            }

            var count = parseInt($("#<%=hfCount.ClientID %>").val());
            if (count <= 5) {
                $("#<%=hfCount.ClientID %>").val(count - 1);
            }
        }
    }
    
</script>

<img src="<%=RequiredImageUrl %>" align="absMiddle" style="float: left; margin-top: 10px;" />
<div style="">
    <!--删除图片的ID 根据此ID删除-->
    <asp:TextBox runat="server" ID="txtDelIdArgs" Style="display: none"></asp:TextBox>
    <!--已存在图片-->
    <asp:TextBox runat="server" ID="txtImgIdArgs" Style="display: none"></asp:TextBox>
    <asp:TextBox runat="server" ID="txtImgUrlArgs" Style="display: none"></asp:TextBox>
    <asp:TextBox runat="server" ID="txtImgRemarkArgs" Style="display: none"></asp:TextBox>
    <asp:TextBox runat="server" ID="txtImgID" Style="display: none;"></asp:TextBox>
    <!--添加图片-->
    <asp:TextBox runat="server" ID="txtAddImgUrlArgs" Style="display: none"></asp:TextBox>
    <asp:TextBox runat="server" ID="txtAddImgRemarParamIDkArgs" Style="display: none"></asp:TextBox>
    <!--上传模板图片控件-->
    <div style="height: 55px; width: 210px; border: 1px dashed #999999; background-color: #FFFFFF;
        padding: 5px 5px 5px 5px;">
         <span style="font-size: 95%; color: #666666" id="tipsSpan">※<%=Tips%></span>
        <!--上传模板图片控件-->
        <input type="file" name="uploadify<%=PhotoDivID %>" id="uploadify<%=PhotoDivID %>" />&nbsp;
    </div>
    <div id="fileQueue<%=PhotoDivID %>" style="width: 100%">
    </div>
    <div class="uploadMultiPhotoDiv" id="<%=PhotoDivID %>">
        <%=InitText %>
    </div>
    <!--图片数量判断-->
    <asp:TextBox runat="server" ID="txtAllImage" Style="display: none"></asp:TextBox>
      <asp:HiddenField runat="server" ID="hfCount" Value="0"/>
</div>
